//全局唯一的一个值班记录内容填写对话框
var zbjlSuperDlg;

function loadZbjlDlg(name){
	var zbjlWriteContentHTML = '<div id="zbjlWriteDiv" style="position:absolute;width:450px;height:250px;left:13px;top:33px;">'+
									'<table style="position:absolute;top:10px;left:10px;">'+
									'<caption>值班记录</caption>'+
									'<tr><td>值班人员</td><td><input type="text" id="zbry_name" value="'+name+'" disabled="disabled"/></td><td>带班领导</td><td><input type="text" value="徐振坤" disabled="disabled"/></td></tr>'+
									'<tr><td>值班日期</td><td><input type="text" id="zbrq_time"/></td><td>记录时间</td><td><input type="text" id="zbsj_time"/></td></tr>'+
									'<tr><td>记录类别</td><td colspan="3"><input type="radio" name="leibie" checked="checked" value="0">无灾&nbsp;<input type="radio" name="leibie" value="1">有灾&nbsp;<input type="radio" name="leibie" value="2">其他&nbsp;</td></tr>'+
									'<tr><td>日志详情</td><td colspan="3"><textarea rows="3" cols="2" id="zbrz_xq" style="width:100%"></textarea></td></tr>'+
									'<tr><td>应急处置</td><td colspan="3"><textarea rows="3" cols="2" id="yjcz_result" style="width:100%"></textarea></td></tr>'+
									'</table>'+
									'<div id="tijiao_button" style="position:absolute;bottom:10px;right:10px;width:50px;height:22px;background-color:#225485;line-height:22px;text-align:center;cursor:pointer;">确定</div>'+
									'</div>';
	zbjlSuperDlg = $.dialog({
		title: '值班记录填写',
		content: zbjlWriteContentHTML,
		dlgDivId: "zbjlWriteContentHTML",
		resize: false,
		max: false,
		left:"400px",
		top:'200px',
		width:'450px',
		height:'250px',
		min:zbjlWriteDlgMin,
		init:zbglSuperDlgInit
	});
}


//最小化的函数，飞到固定的位置
function zbjlWriteDlgMin(){
	//隐藏对话框
	zbjlSuperDlg.DOM.wrap.animate({ top: '1050px', left: '0px', opacity: 0 }, 700, function(){
		//创建div，即最小化菜单项
		createZbjlMinDiv(zbjlSuperDlg);
	});
}

//创建div框，最小化的地方
function createZbjlMinDiv(dialog){
	//完成最小化菜单项的组装
	var minDiv = $("<div>"+dialog.config.title+"</div>");	
	minDiv.attr("title","点击还原");
	minDiv.attr("style","position:absolute;left:5px;bottom:130px;font-size:12px;border:1px solid black;background-color:yellow;cursor:pointer;");
	$("body").append(minDiv);
	minDiv.click(function(){
		dialog.DOM.wrap.animate({ top: dialog.config.top, left:dialog.config.left, opacity: 1 }, 700, function(){
			minDiv.remove();
		});
	})
}


//对话框初始化，进行赋值
function zbglSuperDlgInit(){
	var date = new Date();
	//对日期赋值
	var dateStr = date.getFullYear()+"年"+(date.getMonth()+1)+"月"+date.getDate()+"日";
	$("#zbrq_time").attr("value",dateStr).attr("disabled","disabled");
	giveValueToTime();
	//将对话框本身的关闭按钮置干掉
	$("#zbjlWriteContentHTML .ui_close").remove();
	
	$("#tijiao_button").click(zbjl_tijiaoFunc);
}

//分、秒的赋值
function giveValueToTime(){
	var date = new Date();
	var timeStr = date.getHours()+"时"+checkTime(date.getMinutes())+"分"+checkTime(date.getSeconds())+"秒";
	$("#zbsj_time").attr("value",timeStr).attr("disabled","disabled");
	setTimeout('giveValueToTime()',500);
}

//分、秒的补偿函数
function checkTime(i)
{
	if (i<10) 
	  {i="0" + i}
	  return i
	}

//点击确定按钮之后，提交信息
function zbjl_tijiaoFunc(){
	var zbry = $("#zbry_name").attr("value");
	var lingdao = "徐振坤";
	var zbrq = $("#zbrq_time").attr("value");
	var zbsj = $("#zbsj_time").attr("value");
	var leibie = $("input:radio[name='leibie']:checked").val();
	var zbrz = $("#zbrz_xq").attr("value");
	if(zbrz==""){
		alert("请您必须填写值班日志才能提交！");
		return;
	}
	var yjcz_result = $("#yjcz_result").attr("value");
	var url = "insertZbjlToDB.shtml";
	var obj = {
			zbry:zbry,
			lingdao:lingdao,
			zbrq:zbrq,
			zbsj:zbsj,
			leibie:leibie,
			zbrz:zbrz,
			yjcz_result:yjcz_result
	};
	$.post(url,obj,function(res){
		if(res=="true"){
			alert("填写成功");
			//将对话框最小化，同时，将数据清空
			zbjlWriteDlgMin();
			$("#zbrz_xq").attr("value","");
			$("#yjcz_result").attr("value","");
		}else{
			alert("填写失败");
		}
	});
}



	
